/** \file Utils.cc
 * Definitions for the class Utils.
 *
 * (c) Copyright  Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Utils.cc 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */

#include "Utils.hh"
#include <string.h>


using namespace std;
using namespace TC;


TC_IDENT("$Id$");


//! Get string description of the error number given
string TC::Errno2String(int errnum)
{
  // strerror() is part of the C89 standard 

  const size_t BufMax = 256;
  char buf[BufMax];
  
#if TC_PLAT_Win32
  if(!strerror_s(buf,BufMax,errnum))
#else    
  if(!strerror_r(errnum,buf,BufMax))
#endif    
    return string(static_cast<const char*>(buf));
  else 
    return string();
}


const char* TC::Errno2Str(int errnum)
{
  const size_t BufMax = 256;
  static TC_THREAD_LOCAL char buf[BufMax];

#if TC_PLAT_Win32
  strerror_s(buf,BufMax,errnum);
#else    
  strerror_r(errnum,buf,BufMax);
#endif    

  return buf;
}
